home *** CD-ROM | disk | FTP | other *** search
/ Power CD / Power CD ATARI-Rechner Lieben.iso / SPEZIAL / GEMVIEW / VERSION.3 / MODULS.SRC / CONVMODL / CONVERT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-22  |  14.5 KB  |  525 lines

  1. /* GEM-View 3.00 CONVERTATION Modul: !!!!! Primitives Beispiel !!!!!
  2.    (c) 22.10.1993 by Dieter Fiebelkorn
  3.                      GrĂ¼ner Weg 29a
  4.                      D-45768 Marl
  5.                      (GERMANY)
  6. */
  7.  
  8. #include <stdio.h>
  9. #include "imageopt.h"
  10. #include "moduls.h"
  11.  
  12.  
  13.  
  14. extern int slct_morenames(int mode, int num, void *ptr);
  15.  
  16.  
  17. static CONV_Structure *g_convS;
  18. static char           selectric[4096], newFileName[250];
  19. static char           loadPathname[4096], destinationPath[250];
  20.  
  21.  
  22.  
  23. char *dup_string(char *s)
  24. {
  25.     char *d;
  26.  
  27.     if (!s)
  28.         return(NULL);
  29.     d= (char *)g_convS->memory.malloc(strlen(s) + 1);
  30.     if (d)
  31.         strcpy(d, s);
  32.     else
  33.         d = s;
  34.     return(d);
  35. }
  36.  
  37.  
  38.  
  39. char *get_Filename2(char *pathname, int first)
  40. {
  41.     static char  file[220];
  42.     static char *name;
  43.     static char  mode;
  44.     char        *str;
  45.  
  46.     if (first)
  47.     {
  48.         if (pathname == NULL)
  49.             return(NULL);
  50.         name = pathname;
  51.         mode = ' ';
  52.     }
  53.     else
  54.     {
  55.         if (name == NULL)
  56.             return(NULL);
  57.     }
  58.  
  59.     if (*name == '\0' || (mode != ',' && mode != ' '))
  60.         return(NULL);
  61.     
  62.     if (mode == ',')
  63.     {
  64.         str = file + strlen(file);
  65.         while (str != file && *str != '\\')
  66.             str--;
  67.         if (*str == '\\')
  68.             *++str = '\0';
  69.         else
  70.             *str = '\0';
  71.         goto skip;
  72.     }
  73.     if (mode == ' ')
  74.     {
  75.         file[0] = '\0';
  76. skip:
  77.         str = name;
  78.         while(*str != ',' && *str != ' ' && *str != '\0')
  79.             str++;
  80.         mode = *str;
  81.         *str = '\0';
  82.         strcat(file, name);
  83.         *str++ = mode;
  84.         name = str;
  85.     }
  86.  
  87.     return(file);
  88. }
  89.  
  90.  
  91.  
  92. char *get_Filename3(char *pathname, int first)
  93. {
  94.     static char  file[220];
  95.     static char *name;
  96.     static char  mode;
  97.     char        *str;
  98.  
  99.     if (first)
  100.     {
  101.         if (pathname == NULL)
  102.             return(NULL);
  103.         name = pathname;
  104.         mode = ' ';
  105.     }
  106.     else
  107.     {
  108.         if (name == NULL)
  109.             return(NULL);
  110.     }
  111.  
  112.     if (*name == '\0' || (mode != ',' && mode != ' '))
  113.         return(NULL);
  114.     
  115.     if (mode == ',')
  116.     {
  117.         str = file + strlen(file);
  118.         while (str != file && *str != '\\')
  119.             str--;
  120.         if (*str == '\\')
  121.             *++str = '\0';
  122.         else
  123.             *str = '\0';
  124.         goto skip;
  125.     }
  126.     if (mode == ' ')
  127.     {
  128.         file[0] = '\0';
  129. skip:
  130.         str = name;
  131.         while(*str != ',' && *str != ' ' && *str != '\0')
  132.             str++;
  133.         mode = *str;
  134.         *str = '\0';
  135.         strcat(file, name);
  136.         *str++ = mode;
  137.         name = str;
  138.     }
  139.  
  140.     return(file);
  141. }
  142.  
  143.  
  144.  
  145. char *get_Filename(char *pathname, int first)
  146. {
  147.     DTA         *dta, my_dta;
  148.     static int   my_first;
  149.     static char *wildcards = NULL;
  150.     int          count;
  151.     char        *str, *tmp, path[220];
  152.  
  153. try_next:
  154.     if (first || wildcards == NULL)
  155.     {
  156.         str = wildcards = get_Filename2(pathname, first);
  157.         if (wildcards == NULL)
  158.             return(NULL);
  159.         
  160.         my_first = 1;
  161.         
  162.         wind_update(BEG_UPDATE);
  163.         wind_update(BEG_MCTRL);
  164.         dta = Fgetdta();
  165.         Fsetdta(&my_dta);
  166.  
  167.         strcpy(path, str);
  168.         strcpy(selectric, str);
  169.         tmp = strrchr(path, '\\');
  170.         if (tmp == NULL)
  171.             tmp = path;
  172.         if (tmp[strcspn(tmp, "*?")] != 0)
  173.         {
  174.             if (*tmp == '\\')
  175.                 *tmp++ = 0;
  176.             if (Fsfirst(str, 0x00) == 0)
  177.             {
  178.                 count = 99;
  179.                 if (tmp != path)
  180.                 {
  181.                     strcpy(selectric, path);
  182.                     strcat(selectric, "\\");
  183.                     strcat(selectric, my_dta.d_fname);
  184.                 } else
  185.                     strcpy(selectric, my_dta.d_fname);
  186.                 while (count > 0 && Fsnext() == 0)
  187.                 {
  188.                     strcat(selectric, ",");
  189.                     strcat(selectric, my_dta.d_fname);
  190.                     count--;
  191.                 }
  192.             }
  193.         }
  194.  
  195.         Fsetdta(dta);
  196.         wind_update(END_MCTRL);
  197.         wind_update(END_UPDATE);
  198.     }
  199.  
  200.     str = wildcards = get_Filename3(selectric, my_first);
  201.     if (wildcards == NULL)
  202.         goto try_next;
  203.  
  204.     my_first = 0;
  205.     return(str);
  206. }
  207.  
  208.  
  209.  
  210. int TOS_Version(void)
  211. {
  212.   SYSHDR **_sysbase = (SYSHDR **)0x04F2;
  213.   long    stack;
  214.   int     version;
  215.   
  216.   stack = Super(NULL);
  217.   version = (*_sysbase)->os_base->os_version;
  218.   Super((void *)stack);
  219.   return(version);
  220. }
  221.  
  222.  
  223.  
  224. int get_FileName(char *pathname, char *extention, char *newfilename, char *message, int file_need, int multiple)
  225. {
  226.     char        path[250], tmp_path[220];
  227.     int         fsel_but, is_slct_da;
  228.     long        str_len, restorePath;
  229.     char        filename[20], *str;
  230.     
  231.     restorePath = FALSE;
  232.     memset(path, '\0', 250L);
  233.     path[0] = Dgetdrv() + 'A';
  234.     path[1] = ':';
  235.     Dgetpath(&path[2], 0);
  236.     if (path[2] != '\\')
  237.     {
  238.         memmove(&path[3], &path[2], strlen(path) - 1);
  239.         path[2] = '\\';
  240.     }
  241.     if (path[strlen(path)-1] != '\\')
  242.         strcat(path, "\\");
  243.     
  244.     if (pathname[0] == '\0')
  245.     {
  246.         tmp_path[0] = '\0';
  247.         strcpy(pathname, path);
  248.     }
  249.     else
  250.     {
  251.         str = pathname;
  252.         while(*str != ',' && *str != ' ' && *str != '\0')
  253.             str++;
  254.         *str = '\0';
  255.         strcpy(tmp_path, pathname);
  256.         while(str != pathname && *str != '\\')
  257.             str--;
  258.         if (*str == '\\')
  259.             *++str = '\0';
  260.         restorePath = TRUE;
  261.     }
  262.  
  263.     filename[0] = '\0';
  264.     if (extention == NULL)
  265.         strcat(pathname, "*.*");
  266.     else
  267.         strcat(pathname, extention);
  268.     if (newfilename == NULL)
  269.         strcpy(filename, "");
  270.     else
  271.         strcpy(filename, newfilename);
  272.     g_convS->events.evntHandle(2);
  273.  
  274.     if (file_need)
  275.         is_slct_da = slct_morenames(1, multiple ? 100 : 1, selectric);
  276.     else
  277.         is_slct_da = 0;
  278.     selectric[0] = '\0';
  279.     wind_update(BEG_UPDATE);
  280.     wind_update(BEG_MCTRL);
  281.     g_convS->diawin.reset_dialogCol(TRUE);
  282.     if (TOS_Version() >= 0x0104)
  283.         fsel_exinput(pathname, filename, &fsel_but, message);
  284.     else
  285.         fsel_input(pathname, filename, &fsel_but);
  286.     g_convS->diawin.reset_dialogCol(FALSE);
  287.     wind_update(END_MCTRL);
  288.     wind_update(END_UPDATE);
  289.  
  290.     g_convS->events.evntHandle(2);
  291.     if (fsel_but == 0)
  292.         goto exit;
  293.     if (is_slct_da)
  294.     {
  295.         if (selectric[0] == '\0' && filename[0] != '\0')
  296.             strcpy(selectric, filename);
  297.         if (file_need && selectric[0] == '\0')
  298.             goto exit;
  299.     }
  300.     else
  301.     {
  302.         if (file_need && filename[0] == '\0')
  303.         {
  304. exit:
  305.             strcpy(pathname, tmp_path);
  306.             return(0);
  307.         }
  308.     }
  309.     
  310.     str_len = strlen(pathname);
  311.     while ((str_len > 1) && (pathname[str_len-1] != '\\'))
  312.         str_len--;
  313.     pathname[str_len] = '\0';
  314.     if (pathname[1] != '\0')
  315.     {
  316.         if (restorePath)
  317.         {
  318.             Dsetdrv(path[0] - 'A');
  319.             Dsetpath(&path[2]);
  320.         }
  321.         else
  322.         {
  323.             pathname[str_len-1] = '\0';
  324.             Dsetdrv(pathname[0] - 'A');
  325.             Dsetpath(&pathname[2]);
  326.             pathname[str_len-1] = '\\';
  327.         }
  328.     }
  329.  
  330.     if (file_need)
  331.     {
  332.         if (is_slct_da)
  333.         {
  334.             strcpy(&pathname[str_len], selectric);
  335.             str = &pathname[str_len];
  336.             while(*str != '\0')
  337.             {
  338.                 if (*str == ' ')
  339.                     *str = ',';
  340.                 str++;
  341.             }
  342.         } else
  343.             strcpy(&pathname[str_len], filename);
  344.     }
  345.     
  346.     return(1);
  347. }
  348.  
  349.  
  350.  
  351. ImageOptions *gvw_convert(CONV_Structure *convS)
  352. {
  353.     OBJECT       *tree;
  354.     ImageOptions *list = NULL, *end, *new;
  355.     char         *filename, *file, *str;
  356.     char          destFormatFile[20],
  357.                   destFormatName[20], ext[8];
  358.     int           xdial, ydial, wdial, hdial,
  359.                   exit_obj, borderx, bordery,
  360.                   destFormatType, newType;
  361.     
  362.     g_convS = convS;
  363.     loadPathname[0] = 0;
  364.     destinationPath[0] = 0;
  365.     destFormatFile[0] = 0;
  366.     destFormatName[0] = 0;
  367.     destFormatType = 1;
  368.     
  369.     if (rsrc_load("CONVERT.RSC") == 0)
  370.         return(NULL);
  371.     if (rsrc_gaddr(R_TREE, CONVPATH, &tree) == 0)
  372.         return(NULL);
  373.     if (convS->versions.aes_version >= 0x0340) {
  374.         if (convS->screen_depth > 1) {
  375.             tree[0].ob_spec.obspec.fillpattern = 0;
  376.             tree[0].ob_spec.obspec.interiorcol = 0;
  377.         }
  378.         tree[1].ob_state &= ~OUTLINED;
  379.     }
  380.  
  381.     strcpy(tree[PTHSRC].ob_spec.tedinfo->te_ptext, loadPathname);
  382.     strcpy(tree[PTHDST].ob_spec.tedinfo->te_ptext, destinationPath);
  383.     strcpy(tree[PTHFORMA].ob_spec.tedinfo->te_ptext, destFormatName);
  384.  
  385.     
  386.     wind_update(BEG_UPDATE);
  387.     wind_update(BEG_MCTRL);
  388.     convS->diawin.reset_dialogCol(TRUE);
  389.     form_center(tree, &xdial, &ydial, &wdial, &hdial);
  390.     objc_offset(tree, ROOT, &borderx, &bordery);
  391.     borderx -= xdial;
  392.     bordery -= ydial;
  393.     form_dial(FMD_START, 0, 0, 0, 0, xdial, ydial, wdial, hdial);
  394.     form_dial(FMD_GROW, 0, 0, 0, 0, xdial, ydial, wdial, hdial);
  395.     objc_draw(tree, ROOT, MAX_DEPTH, xdial, ydial, wdial, hdial);
  396.  
  397.     do {
  398.         exit_obj = form_do (tree, 0) & 0x7fff;
  399.         objc_offset(tree, ROOT, &xdial, &ydial);
  400.         xdial -= borderx;
  401.         ydial -= bordery;
  402.         tree[exit_obj].ob_state &= ~SELECTED;
  403.         if (exit_obj == PTHOK) {
  404.             if (loadPathname[0] == '\0')
  405.                 exit_obj = convS->events.alert(1, "[2][ | Please choose File(s)! | ][   OK   ]");
  406.             if (destinationPath[0] == '\0')
  407.                 exit_obj = convS->events.alert(1, "[2][ | Please choose dest. path! | ][   OK   ]");
  408.             if (destFormatName[0] == '\0')
  409.                 exit_obj = convS->events.alert(1, "[2][ | Please choose dest. format! | ][   OK   ]");
  410.             objc_draw (tree, ROOT, MAX_DEPTH, xdial, ydial, wdial, hdial);
  411.         }
  412.  
  413.         if (exit_obj == PTHMONO || exit_obj == PTHCOLOR || exit_obj == PTHTC) {
  414.             tree[exit_obj].ob_state |= SELECTED;
  415.             newType = exit_obj - PTHMONO;
  416.             if (newType != destFormatType) {
  417.                 destFormatType = newType;
  418.                 destFormatName[0] = 0;
  419.                 strcpy(tree[PTHFORMA].ob_spec.tedinfo->te_ptext, destFormatName);
  420.                 objc_draw (tree, PTHFORMA, MAX_DEPTH, xdial, ydial, wdial, hdial);
  421.             }
  422.         }
  423.         
  424.         if (exit_obj == PTHSRC || exit_obj == PTHDST || exit_obj == PTHFORMA) {
  425.             wind_update(END_MCTRL);
  426.             wind_update(END_UPDATE);
  427.  
  428.             if (exit_obj == PTHSRC) {
  429.                 if (get_FileName(loadPathname, "*.*", "IMG's", ">> Select images to convert <<", TRUE, TRUE))
  430.                     strncpy(tree[PTHSRC].ob_spec.tedinfo->te_ptext, loadPathname, tree[PTHSRC].ob_spec.tedinfo->te_txtlen-1);
  431.             }
  432.             if (exit_obj == PTHDST) {
  433.                 if (get_FileName(destinationPath, "*.*", "DestZiel", ">> Select destination path <<", FALSE, FALSE))
  434.                     strncpy(tree[PTHDST].ob_spec.tedinfo->te_ptext, destinationPath, tree[PTHDST].ob_spec.tedinfo->te_txtlen-1);
  435.             }
  436.             if ( exit_obj == PTHFORMA) {
  437.                 switch (destFormatType) {
  438.                     case 0:
  439.                         if (convS->diawin.getMSaving("Destiantion format", ext, destFormatName, destFormatFile))
  440.                             strcpy(tree[PTHFORMA].ob_spec.tedinfo->te_ptext, destFormatName);
  441.                         break;
  442.                     case 1:
  443.                         if (convS->diawin.getCSaving("Destiantion format", ext, destFormatName, destFormatFile))
  444.                             strcpy(tree[PTHFORMA].ob_spec.tedinfo->te_ptext, destFormatName);
  445.                         break;
  446.                     case 2:
  447.                         if (convS->diawin.getTSaving("Destiantion format", ext, destFormatName, destFormatFile))
  448.                             strcpy(tree[PTHFORMA].ob_spec.tedinfo->te_ptext, destFormatName);
  449.                         break;
  450.                 }
  451.             }
  452.  
  453.             wind_update(BEG_UPDATE);
  454.             wind_update(BEG_MCTRL);
  455.             graf_mouse(0, NULL);
  456.             objc_draw (tree, ROOT, MAX_DEPTH, xdial, ydial, wdial, hdial);
  457.         }
  458.     } while (exit_obj != PTHCAN && exit_obj != PTHOK);
  459.  
  460.     form_dial(FMD_SHRINK, 0, 0, 0, 0, xdial, ydial, wdial, hdial);
  461.     form_dial(FMD_FINISH, 0, 0, 0, 0, xdial, ydial, wdial, hdial);
  462.     convS->diawin.reset_dialogCol(FALSE);
  463.     wind_update(END_MCTRL);
  464.     wind_update(END_UPDATE);
  465.     convS->events.evntHandle(2);
  466.     rsrc_free();
  467.  
  468.     if (exit_obj == PTHCAN)
  469.         return(NULL);
  470.  
  471.  
  472.     if ((filename = get_Filename(loadPathname, 1)) != NULL)
  473.     {
  474.         do
  475.         {
  476.             new = convS->memory.newImageOptions();
  477.             if (new == NULL)
  478.                 break;
  479.  
  480.             file = strrchr(filename, '\\');
  481.             file++;
  482.             str = strchr(file, '.');
  483.             if (str != NULL)
  484.                 *str = '\0';
  485.             strcpy(newFileName, destinationPath);
  486.             strcat(newFileName, file);
  487.             strcat(newFileName, &ext[1]);
  488.             if (str != NULL)
  489.                 *str = '.';
  490.  
  491.             new->name     = dup_string(filename);
  492.             new->savename = dup_string(newFileName);
  493.             new->save     = 1 + destFormatType;
  494.             if (destFormatType == 0)
  495.                 new->dither = Dither;
  496.             strcpy(new->tc_saver, destFormatFile);
  497.             strcpy(new->color_saver, destFormatFile);
  498.             strcpy(new->mono_saver, destFormatFile);
  499.             if (new->name == NULL || new->savename == NULL)
  500.             {
  501.                 if (new->name)     convS->memory.free(new->name);
  502.                 if (new->savename) convS->memory.free(new->savename);
  503.                 convS->memory.free(new);
  504.                 new = NULL;
  505.             }
  506.             
  507.             if (new != NULL)
  508.             {
  509.                 if (list == NULL)
  510.                 {
  511.                     list = end = new;
  512.                 }
  513.                 else
  514.                 {
  515.                     end->next = new;
  516.                     new->prev = end;
  517.                     end = new;
  518.                 }
  519.             }
  520.         } while ((filename = get_Filename(loadPathname, 0)) != NULL);
  521.     }
  522.     
  523.     return(list);
  524. }
  525.